package com.unisal.java;

public class MostraEstatisticas implements MostraElementos, Observador {

	private Double maxTemp = 0.0;
	private Double minTemp = 200.0;
	private Double tempSum = 0.0;
	private Integer quantidadeDeLeituras = 0;
	@SuppressWarnings("unused")
	private WeatherData weatherData;

	public MostraEstatisticas(WeatherData weatherData) {
		this.weatherData = weatherData;
		weatherData.registraObservador(this);
	}

	@Override
	public void update(Double temp, Double humidity, Double pressure) {
		tempSum += temp;
		quantidadeDeLeituras++;

		if (temp > maxTemp) {
			maxTemp = temp;
		}

		if (temp < minTemp) {
			minTemp = temp;
		}

		mostra();
	}

	@Override
	public void mostra() {
		System.out.println("Media/Max/Min temperature = "
				+ (tempSum / quantidadeDeLeituras) + "/" + maxTemp + "/" + minTemp);
	}
}